/**
 * 
 */
package uniandes.dermatologia.training.activities;

import uniandes.dermatologia.R;
import uniandes.dermatologia.models.PhysicalExamination;
import uniandes.dermatologia.models.PhysicalExamination.Symptom;
import uniandes.dermatologia.singleton.DermatologiaUniandesApp;
import uniandes.dermatologia.training.CaseLogic;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.NavUtils;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.CheckBox;

/**
 * @author Julio
 *
 */
public class SymptomsCaseActivity extends Activity 
{
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_symptoms);
		// Show the Up button in the action bar.
		getActionBar().setDisplayHomeAsUpEnabled(false);
		
		findViewById(R.id.lblSymptomsSelection).setVisibility(View.GONE);
		
		CheckBox cbAlopecia = (CheckBox) findViewById(R.id.cbAlopecia);
		cbAlopecia.setEnabled(false);
		CheckBox cbBlanching = (CheckBox) findViewById(R.id.cbBlanching);
		cbBlanching.setEnabled(false);
		CheckBox cbDesquamation = (CheckBox) findViewById(R.id.cbDesquamation);
		cbDesquamation.setEnabled(false);
		CheckBox cbPain = (CheckBox) findViewById(R.id.cbPain);
		cbPain.setEnabled(false);
		CheckBox cbEdema = (CheckBox) findViewById(R.id.cbEdema);
		cbEdema.setEnabled(false);
		CheckBox cbEruption = (CheckBox) findViewById(R.id.cbEruption);
		cbEruption.setEnabled(false);
		CheckBox cbExcoriation = (CheckBox) findViewById(R.id.cbExcoriation);
		cbExcoriation.setEnabled(false);
		CheckBox cbExfoliation = (CheckBox) findViewById(R.id.cbExfoliation);
		cbExfoliation.setEnabled(false);
		CheckBox cbHemorrhage = (CheckBox) findViewById(R.id.cbHemorrhage);
		cbHemorrhage.setEnabled(false);
		CheckBox cbPigmentation = (CheckBox) findViewById(R.id.cbPigmentation);
		cbPigmentation.setEnabled(false);
		CheckBox cbPruritus = (CheckBox) findViewById(R.id.cbPruritus);
		cbPruritus.setEnabled(false);
		CheckBox cbOther = (CheckBox) findViewById(R.id.cbOtherSymptoms);
		cbOther.setEnabled(false);
		CheckBox cbFever = (CheckBox) findViewById(R.id.cbFever);
		cbFever.setEnabled(false);
		CheckBox cbFacialParalysis = (CheckBox) findViewById(R.id.cbFacialParalysis);
		cbFacialParalysis.setEnabled(false);
		CheckBox cbWeightLoss = (CheckBox) findViewById(R.id.cbWeightLoss);
		cbWeightLoss.setEnabled(false);
		
		DermatologiaUniandesApp app = (DermatologiaUniandesApp)getApplication();
		CaseLogic caseLogic = app.getCurrentCaseLogic();
		PhysicalExamination examination = caseLogic.getExamination();
		
		String[] symptomStrings = examination.getSymptoms().split(" ");
		
		for(String s: symptomStrings)
		{
			if(s.equals(Symptom.alopecia.name()))
			{
				cbAlopecia.setChecked(true);
			}
			else if(s.equals(Symptom.blanching.name()))
			{
				cbBlanching.setChecked(true);
			}
			else if(s.equals(Symptom.desquamation.name()))
			{
				cbDesquamation.setChecked(true);
			}
			else if(s.equals(Symptom.edema.name()))
			{
				cbEdema.setChecked(true);
			}
			else if(s.equals(Symptom.eruption.name()))
			{
				cbEruption.setChecked(true);
			}
			else if(s.equals(Symptom.excoriation.name()))
			{
				cbExcoriation.setChecked(true);
			}
			else if(s.equals(Symptom.exfoliation.name()))
			{
				cbExfoliation.setChecked(true);
			}
			else if(s.equals(Symptom.facial_paralysis.name()))
			{
				cbFacialParalysis.setChecked(true);
			}
			else if(s.equals(Symptom.fever.name()))
			{
				cbFever.setChecked(true);
			}
			else if(s.equals(Symptom.hemorrhage.name()))
			{
				cbHemorrhage.setChecked(true);
			}
			else if(s.equals(Symptom.pain.name()))
			{
				cbPain.setChecked(true);
			}
			else if(s.equals(Symptom.pigmentation.name()))
			{
				cbPigmentation.setChecked(true);
			}
			else if(s.equals(Symptom.pruritus.name()))
			{
				cbPruritus.setChecked(true);
			}
			else if(s.equals(Symptom.weight_loss.name()))
			{
				cbWeightLoss.setChecked(true);
			}
		}
		
		
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.symptoms, menu);
		return true;
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		switch (item.getItemId()) {
		case android.R.id.home:
			// This ID represents the Home or Up button. In the case of this
			// activity, the Up button is shown. Use NavUtils to allow users
			// to navigate up one level in the application structure. For
			// more details, see the Navigation pattern on Android Design:
			//
			// http://developer.android.com/design/patterns/navigation.html#up-vs-back
			//
			NavUtils.navigateUpFromSameTask(this);
			return true;
		}
		return super.onOptionsItemSelected(item);
	}

	public void onClickNext(View v) {
		Intent intent = new Intent(this, PastCaseActivity.class);
		startActivity(intent);
	}

	public void onClickBack(View v) {
		finish();
	}
}
